class Solution
{
public:
    int longestPalindrome(string s)
    {
        int maxLen = 0;
        unordered_map<char, int> charCount;
        for (char c : s)
        {
            ++charCount[c];
        }
        bool singleChar = false;
        for (auto &[c, count] : charCount)
        {
            maxLen += count / 2 * 2;
            if (count & 1)
            {
                singleChar = true;
            }
        }
        if (singleChar)
        {
            ++maxLen;
        }
        return maxLen;
    }
};